/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package 垃.圾;

import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import javax.swing.JFrame;
import z.h.w.jar.kit.method.Num;
import z.h.w.jar.kit.method.Roll;
import z.h.w.jar.kit.clazz.Split;
import z.h.w.jar.kit.method.To;

/**
 *
 * @author EnzoZhong
 */
public class ListTest1 {

      static Double midX = 0.0;
      static Double midY = 0.0;

      /**
       * @param args the command line arguments
       */
      public static void main ( String[] args ) {

            DecimalFormat decimalFormat = new DecimalFormat ( "0.00" );
            String string = Roll.range ( '0' , 'z' );

            final Double diametro = 200.0;
            final Integer intDiametro = diametro.intValue ();
            final Integer bei = 31;

            JFrame jf = new JFrame ();
            jf.setTitle ( "e" );
            jf.setDefaultCloseOperation ( javax.swing.WindowConstants.EXIT_ON_CLOSE );
            final Canvas canvas = new Canvas ();

            canvas.addMouseWheelListener ( new MouseWheelListener () {

                  @Override
                  public void mouseWheelMoved ( MouseWheelEvent mwe ) {
                        Graphics g = canvas.getGraphics ();
                        List< List<CharXY>> finalList = dd ( "1234567890" );
                        for ( List<CharXY> list : finalList ) {
                              for ( CharXY cxy : list ) {
                                    String cha = cxy.getCha ().toString ();
                                    Integer x = new Double ( cxy.getX () * bei + intDiametro ).intValue ();
                                    Integer y = new Double ( cxy.getY () * bei + intDiametro ).intValue ();
                                    System.out.println ( cha + "  " + x + " " + y );
                                    g.drawString ( cha , x , y );
                              }
                        }
                  }

            } );

            jf.add ( canvas );
            jf.setSize ( 800 , 600 );
            canvas.setSize ( 800 , 600 );

            canvas.show ();
            jf.show();


      }

      public static List< List<CharXY>> dd ( String text ) {
            Integer len = text.length ();
            List<Character> arrayList = Arrays.asList ( To.string2CharacterArray ( text ) );
            Double d = Math.sqrt ( Double.valueOf ( len ) ) + 0.5;
            Integer sp = d.intValue ();
            Split<Character> split = new Split<> ( arrayList , sp );
            Double x = 0.0;
            Double y = 0.0;
            List<Character> tempList;
            List< List<CharXY>> finalList = new ArrayList<> ( ( len / sp ) + 1 );
            while ( split.hasNext () ) {
                  tempList = split.next ();
                  List<CharXY> putList = new ArrayList<> ( ( len / sp ) + 1 );
                  x = 0.0;
                  for ( Character ch : tempList ) {
                        putList.add ( transform ( new CharXY ( ch , x , y ) , 0.0 ) );
                        x ++;
                        midX = Math.max ( midX , x / 2 );
                  }
                  y ++;
                  midY = y / 2;
                  System.out.println ( midX + " " + midY );
                  finalList.add ( putList );
            }
            return finalList;
      }

      public static CharXY transform ( CharXY cxy , Double 角度 ) {
            Double x = cxy.getX ();
            Double y = cxy.getY ();
            Double r = Num.求斜边 ( x , y );
            角度 = Math.toDegrees ( 角度 );
            Character cha = cxy.getCha ();

            if ( x > midX ) {
                  if ( y > midY ) {
                        //1
                        return new CharXY ( cha , r * Math.sin ( 角度 ) , r * Math.cos ( 角度 ) );
                  } else if ( y == midY ) {
                        return new CharXY ( cha , 0.0 , r );
                  } else {
                        //2
                        return new CharXY ( cha , r * Math.cos ( 角度 ) , r * Math.sin ( 角度 ) );
                  }
            } else if ( x == midX ) {
                  return new CharXY ( cha , r , 0.0 );
            } else {
                  if ( y < midY ) {
                        //3
                        return new CharXY ( cha , r * Math.sin ( 角度 ) , r * Math.cos ( 角度 ) );
                  } else if ( y == midY ) {
                        return new CharXY ( cha , 0.0 , r );
                  } else {
                        //4
                        return new CharXY ( cha , r * Math.cos ( 角度 ) , r * Math.sin ( 角度 ) );
                  }
            }
      }

      public static class CharXY {

            private Character cha;
            private Double x;
            private Double y;

            public CharXY ( Character cha , Double x , Double y ) {
                  this.cha = cha;
                  this.x = x;
                  this.y = y;
            }

            public void setX ( Double x ) {
                  this.x = x;
            }

            public void setY ( Double y ) {
                  this.y = y;
            }

            public Character getCha () {
                  return cha;
            }

            public Double getX () {
                  return x;
            }

            public Double getY () {
                  return y;
            }

            @Override
            public int hashCode () {
                  int hash = 7;
                  hash = 41 * hash + Objects.hashCode ( this.cha );
                  hash = 41 * hash + Objects.hashCode ( this.x );
                  hash = 41 * hash + Objects.hashCode ( this.y );
                  return hash;
            }

            @Override
            public boolean equals ( Object obj ) {
                  if ( obj == null ) {
                        return false;
                  }
                  if ( getClass () != obj.getClass () ) {
                        return false;
                  }
                  final CharXY other = ( CharXY ) obj;
                  if (  ! Objects.equals ( this.cha , other.cha ) ) {
                        return false;
                  }
                  if (  ! Objects.equals ( this.x , other.x ) ) {
                        return false;
                  }
                  if (  ! Objects.equals ( this.y , other.y ) ) {
                        return false;
                  }
                  return true;
            }

            @Override
            public String toString () {
                  return "{" + "char=" + cha + ", x=" + x + ", y=" + y + '}';
            }

      }

}
